Conversation
CalculatorWhat We're Looking For
|
CheezItMan
reviewed
Feb 9, 2018
| puts "\nEnter the the first number:" | ||
| a = gets.chomp | ||
| while true | ||
| if a.to_f.to_s == a || a.to_i.to_s == a |
There was a problem hiding this comment.
Works great, but I'd encourage you to make a loop that repeats while the input is wrong and not infinitely and then break out when the input is valid. It just makes reading the code flow a little harder.
Also a doesn't make a good variable name. The name doesn't tell anyone what the variable would be used for.
Lastly you also indented too much here. Indent by 1 tab or 2 spaces and be consistent.
| end | ||
| ##### NOT SURE IF THIS SECTION IS NEEDED AT ALL, ESPECIALLY IF I HAVE CONVERTED THE USER INPUT INTO FLOAT/Integer.##### | ||
| # change data types of number to float to account for decimal numbers. | ||
| def num_class(i) |
There was a problem hiding this comment.
If you want to avoid showing a decimal for integer math, then it's necessary.
|
|
||
| # Get another number from the user. | ||
| puts "Give me another number:" | ||
| b = gets.chomp |
There was a problem hiding this comment.
More cryptic variable names noooooooo!!!
| a = num_class(a) | ||
| b = num_class(b) | ||
| #### End of unworthy code which depend upon the previously written uworthy code#### | ||
| # Case Loop |
There was a problem hiding this comment.
A case is not a loop, but a conditional like an if statement.
| else puts "Please enter a number other than '0' when using division" | ||
| end | ||
| #Add support for the modulo operator (10 % 3 = 1). | ||
| when '%' , 'modulo' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Calculator
Congratulations! You're submitting your assignment.
Comprehension Questions